#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:08创建mysql数据库创建表.py
# author: 马国鑫
# datetime:2022/4/17 21:49
# software: PyCharm

"""
this is function  description 
"""

# import module your need
# 导入pymysql
import pymysql
# 创建连接
conn = pymysql.connect(host='localhost', user='root',
                       password='021207',database='python_db', port=3306)
cur = conn.cursor()

sql = """
    create table t_student(
        sno int primary key auto_increment ,
        sname varchar(30) not null,
        age int(2),
        score float(3,1)
    )
"""
try:
    # 执行创建表的sql
    cur.execute(sql)
    print('创建表成功')
except Exception as e:
    print(e)
    print('创建表失败')
finally:
    cur.close()
    conn.close()
